/*
	curl -o key_decrypt.go https://gitee.com/codesprite/gist/raw/master/key_decrypt.go \
	&& go run key_decrypt.go <password> \
	&& rm key_decrypt.go
*/

package main

import (
	"crypto/aes"
	"crypto/cipher"
	"encoding/base64"
	"fmt"
	"os"
)

var keys map[string]string = map[string]string{
	"repo": "7hrHwqGBgsDDN9qJzVssytLt03xlxF3Fmy5Wa+3md53bbpBHL2UwfHPg4goo1tkC+HgG3ccQjfvdfYbt0Z7mUTwP5NPUM6bHudVS4oqPWOpt52Acha1C7/d8fdmYLef6IgPtmWEtEzw5/0xRPVLyDziOguznJlScMignBRkCR8YGkguliDT0cg4F4kFbcI/HackKlczCaAvUagsvzqbSwoKmrXUzx26noe/e5uljon8WBFL9XH2tjfNgFM4wuqsv5dgiI27N/UZ6917OYYp8RfQqde31GWSur6U0jgcGI+Z6e4U8x+EScEKoqbfP9HnrwPcN5rxO9rm80qFsLOa+Ao3wW+OGHyzhwSIcAvTzyRn3/xH6iwouOlgKcmaQQmWGqikf5oKDsVHCSVsuD/XFgsY4JNXOc3xoaeBVBUdlS4xZjTwy4KlmBn1FicQoW76bsKPMuavecHjZR2BEaU7qbS+7CaA+a6HNM/C1bY0x9BwH0T5OPD4kufcEQ9Qd/n11ZePOZ2mKndIe15JtTBL7Px/3hjECvOA86jmZhkp7I3kE6KwhHzIVQ1f2eHuoDVeCOP/YHA7iVxPz4fAc4e1cNGQvNvH6KPKzremYQfbPX/j+B0LyfzgnM+Mvl9JnfJYf1n6p6wKxoRZnu+4alzB5ujAv1KZntfrdYkFB21MPnprVvTBUqiuu/6nGDjKLQlZ8zeSdn8e3NUnDMpNCgsRHrdPemN/bBn50lLpONOEq86ZACOnU2cOsHhgTPD0el/eUZcA3KI7lz+X8eY2mUc46IfLcCOgWACxzSOUNOA2sZppvB5Cv1RZO8jeHgxQ7AaMLHw9gJ3g/mEY47HjVMCAG9i3Pi/LfO0YhXzFm6HWK4pyx0he03nNAbHedydnV7bfBETPQOXIS7NvgGafm+icq3Fw2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0jj6kNmoV2uRMvQeRvD5SrPJ451FxE43okuGMZGXtebBVyjLtJ1tibOIgwgCmfe/j0BvXVslLgW9q76cbE9b4CkuOb3R3q2jAydj1/d+n6oUCNCVLxGXuRRFLmPBPGBfdPLwIj3ZzBDYr/8yj9qp+6pCzzn50pFsJ1EoxtGFTK7sMelZsImwLelGd4xKA4B85ZlT+CQWEokCXbRQAaUkFZ1hfWG39YxRgwKmY4+uaZDWKh+Fjx0UNOBioYpCR26hLz/dAhkjsWEwwTg7+FgK5eDxaVgJ4Pi8uviIu23uxt77V+M9qOL5nu3emsKbjURQKOZchwg7NMAGwQDhVjMZymxfkOtacA0tkhiycSSUsHOJ1H+5lCKzZL5eZhGIiQv3VZ5RIblo7WhwTKxG4gj0E67pN0Y7EXhsVAYtibsnXIG5TjvPQuWU1Rn4XtGAwv7molr/yH7kyNxp12EiFpZfg/OjML8ssfefxb/NSF/xiNOvdGL0bOfcL3XaYLY/aFRYRx/MP5xk1TzANlW+ExwStJ1azafn/+WObOtg+kaeDy4ATazP+7IWaniXeYeBq8puVb7DpHj506PdWtlGtKYz25myrycuLroFo57uX4XjpG9NrJFFHXQd0ZXubk3",
}

const IV string = "f8uiRQWE9o7QKJ9b"

// key length must be 16,24,32
func decrypter(data []byte, key []byte) []byte {
	block, _ := aes.NewCipher(key)
	blockMode := cipher.NewCBCDecrypter(block, []byte(IV))
	result := make([]byte, len(data))
	blockMode.CryptBlocks(result, data)
	result = PKCS7UnPadding(result)
	return result
}

func PKCS7UnPadding(text []byte) []byte {
	unPadding := int(text[len(text)-1])
	return text[:(len(text) - unPadding)]
}

func main() {
	key := os.Args[1]

	for k, v := range keys {
		path := k + ".key"
		f, _ := os.Create(path)
		data, _ := base64.StdEncoding.DecodeString(v)
		data = decrypter(data, []byte(key))
		f.Write(data)
		f.Close()
		os.Chmod(path, 0600)
	}

	fmt.Println("\033[32m[OK]\033[0m for public key:")
	fmt.Println("\033[34mssh-keygen -f <private_key> -y > <public_key>\033[0m")
}
